module vec_factory;
use memory;
use vec;
implicit none;
contains

function make_vec_rand(n) result(ptr);
  implicit none;
  integer, intent(in) :: n;
  real(R14), dimension(:), pointer :: ptr;
  call dbg_info("make_vec_rand()");
  ptr => new_vec(n);   call dbg_vec("new_vec=", ptr);
  call RANDOM_NUMBER(ptr);
  call dbg_vec("RANDOM_NUMBER(ptr)=", ptr);
  return;
end function

function make_vec_step_OLD(min_val, max_val, vsize)  result(vec_p);    implicit none;
  real(R14), dimension(:), pointer :: vec_p;
  integer, intent(in) :: vsize;
  real(R14), intent(in) :: min_val, max_val;
  real(R14) step;
  integer :: i, min_idx, max_idx;
  call dbg_info("load_vec_step()");
  call assert_true("(vsize > 0)=", vsize > 1);
  call assert_true("(min_val < max_val)=", min_val < max_val);
  step = (max_val - min_val) / real(vsize-1);
  vec_p => new_vec(vsize);   call dbg_vec("vec_p=new_vec()=", vec_p);
  min_idx = LBOUND(vec_p, 1);
  max_idx = UBOUND(vec_p, 1);
  vec_p(min_idx) = min_val;
  do i = min_idx + 1, max_idx
    vec_p(i) = vec_p(i-1) + step;
  end do
  call dbg_vec("vec_p=make_vec_step_OLD()=", vec_p);
  return;
end function


end module
